﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BuildPlannerLib.SimEvents
{
    // Derived class of Event for a worker finishing mining at a gas geyser
    public class FinishGasMining : SimEvent
    {
        // Field for the base at which the mining is taking place
        public Base AtBase;

        // Field for the per-trip yield of the geyser being mined
        public int Yield;

        // Constructor with parameters for parent build, base, gas geyser type, and time
        public FinishGasMining(Build build, Base b, int yield, int time)
        {
            Build = build;
            AtBase = b;
            Yield = yield;
            Time = time;
        }

        // Adds an event for returning the gas, checks for workers waiting to mine and has them mine the geyser, otherwise the geyser is set to Idle
        public override void Execute()
        {
            int newTime = Time + 211;
            Build.EventList.Add(new ReturnGas(Build, AtBase, Yield, newTime));

            newTime = Time;

            if (AtBase.GasWorkerStatus[1] > 0)
            {
                AtBase.GasWorkerStatus[1]--;
                newTime += 211;
                Build.EventList.Add(new FinishGasMining(Build, AtBase, Yield, newTime));
            }
            else
            {
                if (Yield == 8)
                {
                    AtBase.IdleGasGeysers[2]++;
                }
                else if (Yield == 6)
                {
                    AtBase.IdleGasGeysers[1]++;
                }
                else
                {
                    AtBase.IdleGasGeysers[0]++;
                }
            }
        }
    }
}
